package org.example.copy.ShallowCopy;



import org.springframework.beans.BeanUtils;

public class Example {
    public static void main(String[] args) {
        try {
            // 创建源对象
            SourceBean srcBean = new SourceBean();
            srcBean.setId(1);
            srcBean.setValue("Original Value");
            srcBean.setInnerBean(new InnerBean("Inner Original Value"));

            // 创建目标对象
            DestinationBean destBean = new DestinationBean();

            // 执行属性复制
            BeanUtils.copyProperties(destBean, srcBean);

            // 修改源对象的 InnerBean 属性
            srcBean.getInnerBean().setValue("Modified Inner Value");

            // 输出结果
            System.out.println("Source Bean Value: " + srcBean.getValue());
            System.out.println("Destination Bean Value: " + destBean.getValue());
            System.out.println("Source Bean Inner Value: " + srcBean.getInnerBean().getValue());
            System.out.println("Destination Bean Inner Value: " + destBean.getInnerBean().getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}